home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / OutOfContextMenus / Source / CPigLatinBehavior.cp < prev    next >
Encoding:
Text File  |  1999-06-25  |  3.0 KB  |  113 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CPigLatinBehavior.cp                 ©1999 Eric Traut
  3. // ===========================================================================
  4.  
  5. #include "CPigLatinBehavior.h"
  6. #include "CShadowWindow.h"
  7.  
  8. #include <UMemoryMgr.h>
  9.  
  10. // ---------------------------------------------------------------------------
  11. //        • CPigLatinBehavior
  12. // ---------------------------------------------------------------------------
  13.  
  14. CPigLatinBehavior::CPigLatinBehavior(
  15.     CShadowWindow &        inShadowWindow)
  16.     :    COffscreenBehavior(inShadowWindow, true)
  17. {
  18. }
  19.  
  20.  
  21. // ---------------------------------------------------------------------------
  22. //        • RenderToGWorld
  23. // ---------------------------------------------------------------------------
  24.  
  25. Boolean
  26. CPigLatinBehavior::RenderToGWorld(
  27.     StGWorldLocker &        inBackingLocker,
  28.     StGWorldLocker &        inRenderingLocker)
  29. {
  30.     COffscreenBehavior::RenderToGWorld(inBackingLocker, inRenderingLocker);
  31.     
  32.     return true;
  33. }
  34.  
  35.  
  36. // ---------------------------------------------------------------------------
  37. //        • ConvertTextToPigLatin
  38. // ---------------------------------------------------------------------------
  39.  
  40. void
  41. CPigLatinBehavior::ConvertTextToPigLatin(
  42.     const char *        inTextBuf,
  43.     UInt32                inByteCount,
  44.     Handle                outPigLatin)
  45. {
  46.     ::SetHandleSize(outPigLatin, inByteCount);
  47.     ThrowIfMemError_();
  48.     
  49.     // fix me - need to finish
  50.     ::BlockMoveData(inTextBuf, *outPigLatin, inByteCount);
  51.     
  52.     if (inByteCount > 0)
  53.         outPigLatin[0][0] = 'a';
  54. }
  55.  
  56.  
  57. // ---------------------------------------------------------------------------
  58. //        • DoQDText
  59. // ---------------------------------------------------------------------------
  60.  
  61. void
  62. CPigLatinBehavior::DoQDText(
  63.     CGrafPtr        inOrigPort,
  64.     short             inByteCount, 
  65.     Ptr             inTextBuf, 
  66.     Point             inNumer, 
  67.     Point             inDenom)
  68. {
  69.     StHandleBlock        pigLatinText(0, true, true);
  70.     ConvertTextToPigLatin(inTextBuf, inByteCount, pigLatinText);
  71.     {
  72.         StHandleLocker        locker(pigLatinText);
  73.         UInt32        newByteCount = ::GetHandleSize(pigLatinText);
  74.         COffscreenBehavior::DoQDText(inOrigPort, newByteCount, *pigLatinText, inNumer, inDenom);
  75.     }
  76. }
  77.  
  78.  
  79. // ---------------------------------------------------------------------------
  80. //        • DoQDTxMeas
  81. // ---------------------------------------------------------------------------
  82.  
  83. SInt16
  84. CPigLatinBehavior::DoQDTxMeas(
  85.     CGrafPtr        inOrigPort,
  86.     SInt16             inByteCount, 
  87.     Ptr             inTextAddr, 
  88.     Point *            inNumer, 
  89.     Point *            inDenom, 
  90.     FontInfo *        inInfo)
  91. {
  92.     StHandleBlock        pigLatinText(0, true, true);
  93.     ConvertTextToPigLatin(inTextAddr, inByteCount, pigLatinText);
  94.  
  95.     {
  96.         StHandleLocker        locker(pigLatinText);
  97.         UInt32        newByteCount = ::GetHandleSize(pigLatinText);
  98.         return COffscreenBehavior::DoQDTxMeas(inOrigPort, newByteCount, *pigLatinText, inNumer, inDenom, inInfo);
  99.     }
  100. }
  101.  
  102.  
  103. // ---------------------------------------------------------------------------
  104. //        • ShouldEnableRestoreMenu
  105. // ---------------------------------------------------------------------------
  106.  
  107. Boolean
  108. CPigLatinBehavior::ShouldEnableRestoreMenu(void)
  109. {
  110.     return false;
  111. }
  112.  
  113.